/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.ytbolg.mcxa.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextArea;
//import net.ytbolg.mcxa.unZipThread;

/**
 *
 * @author root
 */
public class OutKeeper implements Runnable {

    private JTextArea jta;
    private Process p;
    private boolean outmode = false;

    public OutKeeper(Process s) {
        p = s;
    }

    public OutKeeper(Process s, JTextArea jta) {
        this.jta = jta;
        outmode = true;
        p = s;
    }

    @Override
    public void run() {
        try {
            InputStream isp = p.getInputStream();
            InputStreamReader isr = new InputStreamReader(isp);
            //   BufferedReader br=new BufferedReader(isr);
            int c;
            while ((c = isr.read()) != -1) {
                if (outmode) {
                    jta.setText(jta.getText() + (char) c);
                } else {
                    System.out.print((char) c);
                }
            }
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        } catch (IOException ex) {
            ex.printStackTrace();
//   Logger.getLogger(unZipThread.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
